Skip to content

Fix some wrong dataState values with network-only and errorPolicy: "none" queries - #13381

Open
jerelmiller wants to merge 33 commits into
release-4.3from
jerel/network-only-errors
Open

Fix some wrong dataState values with network-only and errorPolicy: "none" queries#13381
jerelmiller wants to merge 33 commits into
release-4.3from
jerel/network-only-errors

Conversation

@jerelmiller

@jerelmiller jerelmiller commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of errors in queries using @defer and @stream.
    • Prevented partial cached data from appearing in network-only queries after deferred errors.
    • Preserved the correct streaming state when deferred content encounters errors.
    • Prevented duplicate or invalid updates after incremental boundaries complete.
    • Truncated streamed lists safely when later items cause non-nullability errors.
  • API Updates

    • Enhanced incremental query metadata with pending-item details and stream information.
    • Replaced legacy pending-item accessors with more descriptive streaming metadata.

@apollo-librarian

apollo-librarian Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 92852a653a04c990be3ebe32
Build Logs: View logs


✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@changeset-bot

changeset-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: afeff3f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 1fc133b3-982d-4400-bf0f-c18b8d5e7984

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The change updates incremental request metadata, preserves streaming data states across errors, adjusts network-only cache pruning, and adds regression coverage for deferred and streamed GraphQL responses.

Changes

Incremental streaming state

Layer / File(s) Summary
Incremental request contract
.api-reports/api-report-incremental.api.md, .api-reports/api-report.api.md, src/incremental/types.ts, .api-reports/api-report-core.api.md
IncrementalRequest replaces legacy pending accessors with getPendingWithInfo and streamInfo. New defer and stream metadata types and stream state declarations are added.
Incremental handler state
src/incremental/handlers/graphql17Alpha9.ts
The handler stores stream metadata, reports pending item details, tracks completion delivery status, and publishes stream information through result extensions.
Query cache and error-state flow
src/core/QueryInfo.ts, src/core/QueryManager.ts, src/core/ObservableQuery.ts, src/core/dataStateErrorCache.ts
Query processing uses incremental metadata for streaming state and network-only pruning. GraphQL errors retain their associated data state for later network error handling.
Incremental regression coverage
src/cache/inmemory/__tests__/cache.diff/incremental.test.ts, src/core/__tests__/client.watchQuery/*, src/incremental/handlers/__tests__/graphql17Alpha9/*, .changeset/*
Tests cover deferred errors, cache behavior, resubscription, overlapping boundaries, streamed non-null errors, and combined defer/stream completion. Patch changesets document the fixes.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant IncrementalHandler
  participant QueryInfo
  participant QueryManager
  participant ObservableQuery
  IncrementalHandler->>QueryInfo: provide pending items and streamInfo
  QueryInfo->>QueryInfo: determine streaming state and prune cache data
  QueryManager->>QueryManager: cache GraphQL error with dataState
  QueryManager->>ObservableQuery: throw cached-state-associated error
  ObservableQuery->>ObservableQuery: restore streaming dataState
Loading

Possibly related PRs

Suggested reviewers: phryneas, daleseo

Poem

A rabbit tracks each stream in flight,
Keeps deferred data states right.
Errors bloom, yet states remain,
Cached fields stay off the train.
Tests hop through each boundary bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes to correct dataState values for network-only queries and errorPolicy "none".
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 3, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@apollo/client@13381

commit: afeff3f

@jerelmiller
jerelmiller requested review from DaleSeo and phryneas and removed request for DaleSeo August 3, 2026 23:30
@jerelmiller
jerelmiller marked this pull request as ready for review August 3, 2026 23:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/incremental/handlers/graphql17Alpha9.ts (1)

104-106: 🗄️ Data Integrity & Integration | 🔵 Trivial | 💤 Low value

Avoid Trie["strong"] as a public API.

makeStreamInfoTrie() always creates the stream trie that streamInfo() exposes, so this getter can be simplified instead of depending on the undocumented internal Trie["strong"] property used in two places.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/incremental/handlers/graphql17Alpha9.ts` around lines 104 - 106, Update
the streamInfo getter to return the stream trie created by makeStreamInfoTrie()
directly, removing the _streamInfo["strong"] check and dependency on the
internal Trie["strong"] property while preserving the existing undefined
behavior when no stream info exists.
src/core/QueryInfo.ts (1)

255-256: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Document why only NetworkStatus.refetch bypasses network-only pruning.

NetworkStatus.poll and NetworkStatus.setVariables also come from fresh network calls, but pending @defer/@stream boundaries are still pruned because they are not refetch. Add a short comment next to the isNetworkOnly check that records the intended exclusion set.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/core/QueryInfo.ts` around lines 255 - 256, Add a concise comment beside
the isNetworkOnly check in QueryInfo explaining that only NetworkStatus.refetch
bypasses network-only pruning, while poll and setVariables still prune pending
`@defer/`@stream boundaries despite using fresh network calls. Keep the existing
condition unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.api-reports/api-report-incremental.api.md:
- Around line 13-15: Keep incremental implementation details internal by
updating Incremental.IncrementalRequest so its streamInfo?: StreamInfoTrie is no
longer exposed publicly, either by marking IncrementalRequest internal or
removing the internal trie field. Apply the corresponding API-report changes at
.api-reports/api-report-incremental.api.md ranges 13-15 (anchor), 239-245, and
309-335, plus .api-reports/api-report.api.md ranges 1601-1627 and 1638-1643;
ensure PendingStreamResultWithInfo remains internal-deprecated and no public
report exposes StreamInfoTrie.

In `@src/core/__tests__/client.watchQuery/streamGraphQL17Alpha9.test.ts`:
- Around line 4677-4680: Remove the broad any cast from the
enqueueSubsequentChunk call and provide the stream items with the concrete
Record<string, unknown>/ObjMap<unknown> shape expected by
FormattedIncrementalStreamResult, or cast only the runtime payload to unknown if
necessary. Keep validation of the surrounding
FormattedSubsequentIncrementalExecutionResult intact.

In `@src/incremental/types.ts`:
- Line 65: Update the comment immediately before PendingItemWithInfo to use the
TSDoc form for the `@internal` tag, matching the adjacent internal type
declarations so API extraction recognizes it correctly.

---

Nitpick comments:
In `@src/core/QueryInfo.ts`:
- Around line 255-256: Add a concise comment beside the isNetworkOnly check in
QueryInfo explaining that only NetworkStatus.refetch bypasses network-only
pruning, while poll and setVariables still prune pending `@defer/`@stream
boundaries despite using fresh network calls. Keep the existing condition
unchanged.

In `@src/incremental/handlers/graphql17Alpha9.ts`:
- Around line 104-106: Update the streamInfo getter to return the stream trie
created by makeStreamInfoTrie() directly, removing the _streamInfo["strong"]
check and dependency on the internal Trie["strong"] property while preserving
the existing undefined behavior when no stream info exists.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 2dcb7c78-86a7-453e-bd00-e3c2ae9225d1

📥 Commits

Reviewing files that changed from the base of the PR and between 688681d and d3cdc0e.

📒 Files selected for processing (17)
  • .api-reports/api-report-core.api.md
  • .api-reports/api-report-incremental.api.md
  • .api-reports/api-report.api.md
  • .changeset/chilly-actors-complain.md
  • .changeset/loud-bulldogs-pay.md
  • .changeset/swift-starfishes-know.md
  • src/cache/inmemory/__tests__/cache.diff/incremental.test.ts
  • src/core/ObservableQuery.ts
  • src/core/QueryInfo.ts
  • src/core/QueryManager.ts
  • src/core/__tests__/client.watchQuery/deferGraphQL17Alpha9.test.ts
  • src/core/__tests__/client.watchQuery/streamGraphQL17Alpha9.test.ts
  • src/core/dataStateErrorCache.ts
  • src/incremental/handlers/__tests__/graphql17Alpha9/defer.test.ts
  • src/incremental/handlers/__tests__/graphql17Alpha9/stream.test.ts
  • src/incremental/handlers/graphql17Alpha9.ts
  • src/incremental/types.ts

Comment thread .api-reports/api-report-incremental.api.md Outdated
Comment thread src/core/__tests__/client.watchQuery/streamGraphQL17Alpha9.test.ts Outdated
Comment thread src/incremental/types.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant